﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace TCPIPControl.StructHelper
{
    [Serializable]
    /// <summary>
    /// 加速度数据包
    /// </summary>
    /// 
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct AccData
    {
        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        UInt16 Millisecond;

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData[] CHAccData;
    }


    /// <summary>
    /// ACC通道数据
    /// </summary>
    /// 
   [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct ChannelAccData
    {
        public UInt16 ChID;
        /// <summary>
        /// 原始数据
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 131072)]
        public float[] RawData;
        /// <summary>
        /// FFT频谱
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] FFTAmpDB;
        /// <summary>
        /// FFT幅值
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] FFTAmp;
        /// <summary>
        /// FFT能量值
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] FFTPower;

        /// <summary>
        /// 速度FFT幅值
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] ElocityFFTAmp;

        /// <summary>
        /// 震动加速度总值
        /// </summary>
        public float TotalDB;

        /// <summary>
        /// （大于315hz）高频段总值
        /// </summary>
        public float highDB;

        public float lowDB;

        //1/3倍频程
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3otcaveDB;

        //均方根值 
        public float velocityRMS;
        //平均电压
        public float AverageVol;
        //位移RMS
        public float displacementRMS;
        //一倍频幅值
        public float OneMultiplierAmp;
        //二倍频幅值                                        
        public float TWOMultiplierAmp;
        //三倍频幅值                                                
        public float HalfMultiplierAmp;
        //报警标志                           	
        public byte AlarmFlag;
    }

    public struct ChannelAccData_DataPaket
    {

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_RawData[] RawDatas;

        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        //public ChannelAccData_FFTAmpDB[] FFTAmpDBs;

        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        //public ChannelAccData_FFTAmp[] FFTAmps;


        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        //public ChannelAccData_FFTPower[] FFTPowers;

        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        //public ChannelAccData_ElocityFFTAmp[] ElocityFFTAmps;

    }


    public struct ChannelAccData_RawData_Array
    {


        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_RawData[] RawDatas;



    }


    public struct ChannelAccData_FFTAmpDB_Array
    {


        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_FFTAmpDB[] FFTAmpDBs;

    }





    public struct ChannelAccData_FFTAmp_Array
    {


        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_FFTAmp[] FFTAmps;

    }

    public struct ChannelAccData_FFTPower_Array
    {


        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_FFTPower[] FFTPowers;

    }

    public struct ChannelAccData_ElocityFFTAmp_Array
    {


        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_ElocityFFTAmp[] ElocityFFTAmps;

    }

    public struct ChannelAccData_1_3otcaveDB_Array
    {


        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public ChannelAccData_1_3otcaveDB[] _1_3otcaveDBs;

    }


    public struct ChannelAccData_RawData
    {
        /// <summary>
        /// 原始数据
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 131072)]
        public float[] RawData;
    }

    public struct ChannelAccData_FFTAmpDB
    {
        /// <summary>
        /// FFT频谱
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] FFTAmpDB;
    }


    public struct ChannelAccData_FFTAmp
    {
        /// <summary>
        /// FFT幅值
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] FFTAmp;
    }


    public struct ChannelAccData_FFTPower
    {
        /// <summary>
        /// FFT能量值
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] FFTPower;
    }

    public struct ChannelAccData_ElocityFFTAmp
    {
        /// <summary>
        /// 速度FFT幅值
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] ElocityFFTAmp;
    }

    public struct ChannelAccData_1_3otcaveDB
    {

        //1/3倍频程
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3otcaveDB;
    }


    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack =4)]
    public struct Acceleration_256
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;//结构体末尾值
    }

    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_512
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }

    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_1024
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2048)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }

    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_2048
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4096)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2048)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }


    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_4096
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8192)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4096)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }

    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_8192
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16384)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8192)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;

    }


    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_16384
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32768)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16384)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }

    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_32768
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32768)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }

    /// <summary>
    /// 振动加速度每个结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct Acceleration_65536
    {

        public UInt16 Year;
        public byte Month;
        public byte Day;
        public byte Hour;
        public byte Minute;
        public byte Second;
        public UInt16 MSecond;
        public UInt16 ChannelId;
        public float totaldB;//振动加速度总值
        public float highdB;//高频段总值
        public float lowdB;//低频段总值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
        public float[] _1_3octavedB;//倍频程
        public float velocityRMS;//均方根值
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 131072)]
        public float[] accelerationTimewave;//加速度原始数据
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 65536)]
        public float[] accelerationFFTAmpDB;//加速度FFT频谱
        public UInt16 EndValue;
    }



    /// <summary>
    /// 通道配置
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct ChannelConfig
    {
        public byte ChannelNo;//通道ID
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
        public byte[] ChannelID;//通道名称
        public byte Enable;//通道使能
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
        public byte[] Name;//测点名称
        public byte Direction;//安装方向
        public byte SigType;//信号类型
        public byte SigUnit;//信号单位
        public float Sensitivity;//传感器灵敏度
        public byte SensitivityUnit;//灵敏度单位
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
        public byte[] SensorType;//传感器型号
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
        public byte[] SensorManufacture;//传感器制作商
        public UInt64 SensorNo;//传感器序列号

    }


    /// <summary>
    /// 系统配置
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, Pack = 4)]
    public struct SystemConfig
    {
        public UInt16 SampleRate;//采样频率
        public UInt32 Lines;//线数
        public byte Average;//计算平均次数
        public byte AverageMod;//平均方式
        public byte WindowFunction;//计算窗函数
    }
}
